﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Windows.Controls;
using System.Windows.Data;
using FazaDemo.ViewModels;
using FazaDemo.QL.AbstractQueryModel;
using FazaDemo.QueryModel;

namespace FazaDemo.PL.Wpf
{
    class PlaceGridFactory : DataGridFactory
    {

        private IList<PlaceViewModel> _viewModels;

        public PlaceGridFactory()
        {
            _apiClient = new WebApiClient();
        }

        public PlaceGridFactory(IDgridCustomizer customizer)
        {
            Customizer = customizer;
            _apiClient = new WebApiClient();
        }

        protected override void AddColumns()
        {
            _workDgrid.Columns.Add(new DataGridTextColumn{Header = "Название"});
            _workDgrid.Columns.Add(new DataGridTextColumn { Header = "Альтернативное название" });
            _workDgrid.Columns.Add(new DataGridTextColumn { Header = "Социальное название" });
            _workDgrid.Columns.Add(new DataGridTextColumn { Header = "Виртуальная?" });
            _workDgrid.Columns.Add(new DataGridTextColumn {Header = "ID"});
        }

        protected override void LoadContent()
        {
            _viewModels = _apiClient.GetList<PlaceViewModel>().ToList();
            _workDgrid.ItemsSource = _viewModels;
            var nameColumn = _workDgrid.Columns[0] as DataGridTextColumn;
            nameColumn.Binding = new Binding("Name");
            var altNameColumn = _workDgrid.Columns[1] as DataGridTextColumn;
            altNameColumn.Binding = new Binding("AltName");
            var socNameColumn = _workDgrid.Columns[2] as DataGridTextColumn;
            socNameColumn.Binding = new Binding("SocialName");
            var isVirtualColumn = _workDgrid.Columns[3] as DataGridTextColumn;
            isVirtualColumn.Binding = new Binding("IsVirtual");
            var idColumn = _workDgrid.Columns[4] as DataGridTextColumn;
            idColumn.Binding = new Binding("Id");
        }
    }
}